//
//  MineViewController.m
//  四年
//
//  Created by 中软国际088 on 15/11/3.
//  Copyright © 2015年 小二. All rights reserved.
//

#import "MineViewController.h"
#import "MyTableViewCell.h"
#import "My.h"
#import "SecondaViewController.h"
#import "SecondbViewController.h"
#import "SecondcViewController.h"
#import "SeconddViewController.h"
#import "SecondeViewController.h"
#import "SecondfViewController.h"

@interface MineViewController (){
    UITableView *_tableView;
    NSMutableArray *tableViewArray;
}


@end

@implementation MineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor=[UIColor whiteColor];
    _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStyleGrouped];
    _tableView.showsVerticalScrollIndicator = NO;
    _tableView.dataSource=self;
    _tableView.delegate=self;
    [self header];
    [self.view addSubview:_tableView];
    [self initData];

}

//初始化数据
-(void)initData{
    My *my1=[[My alloc]initWithPicture:@"wodexinxi@2x" andNeirong:@"我的信息"];
    My *my2=[[My alloc]initWithPicture:@"wodekebiao@2x" andNeirong:@"我的课程"];
    My *my3=[[My alloc]initWithPicture:@"wodekaoshi@2x" andNeirong:@"我的考试"];
    My *my4=[[My alloc]initWithPicture:@"wodefabu@2x" andNeirong:@"我的发布"];
    NSArray *arr1=@[my1,my2,my3,my4];
    
    My *my5=[[My alloc]initWithPicture:@"shezhi@2x" andNeirong:@" 设置"];
    NSArray *arr2=@[my5];
    
    My *my6=[[My alloc]initWithPicture:@"bangzhu@2x" andNeirong:@"版本反馈"];
    NSArray *arr3=@[my6];
    tableViewArray=[NSMutableArray arrayWithObjects:arr1,arr2,arr3,nil];
    
}
//设置表头
-(void)header{
    UIView *v=[[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT/3-22)];
    //v.backgroundColor=[UIColor redColor];
    UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(WIDTH/2-50, HEIGHT/30-2, 100, 100)];
    imageView.image=[UIImage imageNamed:@""];
    imageView.backgroundColor=[UIColor redColor];
   
    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(WIDTH/2-40, HEIGHT/6+24, 100, 30)];
    label.text=@"登录/注册";
    label.textColor=[UIColor colorWithRed:62/255.0 green:193/255.0 blue:209/255.0 alpha:1];
    
    _tableView.tableHeaderView=v;
    [v addSubview:imageView];
    [v addSubview:label];
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return tableViewArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray*group=tableViewArray[section];
    return group.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *name=@"cell";
    MyTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:name];
    if (cell==nil) {
        cell=[[MyTableViewCell alloc]init];
        NSArray *group=tableViewArray[indexPath.section];
        My *m=group[indexPath.row];
        cell.myImageView.image=[UIImage imageNamed:m.picure];
        cell.label.text=m.neirong;
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    }
    return cell;

}
//cell点击跳转
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
     SecondaViewController*secondaCtr=[[SecondaViewController alloc]init];
    SecondbViewController*secondbCtr=[[SecondbViewController alloc]init];
    SecondcViewController*secondcCtr=[[SecondcViewController alloc]init];
    SeconddViewController*seconddCtr=[[SeconddViewController alloc]init];
    SecondeViewController*secondeCtr=[[SecondeViewController alloc]init];
    SecondfViewController*secondfCtr=[[SecondfViewController alloc]init];
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];// 取消选中

    if (indexPath.section==0) {
        if (indexPath.row==0) {
            [self.navigationController pushViewController:secondaCtr animated:YES];
        }
        else if (indexPath.row==1){
            [self.navigationController pushViewController:secondbCtr animated:YES];
        }
        else if (indexPath.row==2){
            [self.navigationController pushViewController:secondcCtr animated:YES];
        }
        else if (indexPath.row==3){
            [self.navigationController pushViewController:seconddCtr animated:YES];
        }
    }
    else if(indexPath.section==1){
        [self.navigationController pushViewController:secondeCtr animated:YES];
    }
    else if(indexPath.section==2){
        [self.navigationController pushViewController:secondfCtr animated:YES];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
